package com.uw.tookit;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * This class represents the data object stored in result page.
 * It saves the name, business id, latitude, longitude, open hour, and distance information.
 * It can be passed with activities as extras.
 */
public class ResultPageData implements Parcelable  {
	private String resultName;
	private int business_id;
	private double latitude;
	private double longitude;
	private boolean openNow;
	private double distance;
	
	public ResultPageData() {
		
	}
	
	/**
	 * Create a data object of the result page with the given parameters.
	 * @param resultName name of result
	 * @param business_id business id associated with result
	 * @param latitude latitude of result
	 * @param longitude longitude of result
	 * @param openNow if result place is open now
	 */
	public ResultPageData(String resultName, int business_id, double latitude, double longitude, boolean openNow) {
		this.resultName = resultName;
		this.business_id = business_id;
		this.latitude = latitude;
		this.longitude = longitude;
		this.openNow = openNow;
	}
	
	/**
	 * Get the result name.
	 * @return result name as string
	 */
	public String getResultName() {
		return resultName;
	}
	
	/**
	 * Get the business id associated with the result.
	 * @return business id as integer
	 */
	public int getBusinessId() {
		return business_id;
	}
	
	/**
	 * Get the latitude of the result.
	 * @return latitude as double
	 */
	public double getLatitude() {
		return latitude;
	}
	
	/**
	 * Get the longitude of the result.
	 * @return longitude as double
	 */
	public double getLongitude() {
		return longitude;
	}
	
	/**
	 * Get the "open now" info of the result.
	 * @return if the place is still open
	 */
	public boolean isOpenNow() {
		return openNow;
	}
	
	/**
	 * Set the distance of this result to the current location.
	 * @param distance
	 */
	public void setDistanceFromCurrent(double distance) {
		this.distance = distance;
	}
	
	/**
	 * Get the distance of this result to the current location.
	 * @return distance to current location
	 */
	public double getDistanceFromCurrent() {
		return distance;
	}

	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	/**
	 * Define how the data are flattened as parcel.
	 */
	public void writeToParcel(Parcel out, int flags) {
		out.writeString(resultName);
		out.writeInt(business_id);
		out.writeDouble(latitude);
		out.writeDouble(longitude);
	}
	
	/**
	 * Define how to pass the object as parcel.
	 */
	public static final Parcelable.Creator<ResultPageData> CREATOR = new Parcelable.Creator<ResultPageData>() {    
		public ResultPageData createFromParcel(Parcel in) {
		    return new ResultPageData(in);
		}
		
		public ResultPageData[] newArray(int size) {
		    return new ResultPageData[size];
		}
	};
	
	private ResultPageData(Parcel in) {
		resultName = in.readString();
		business_id = in.readInt();
		latitude = in.readDouble();
		longitude = in.readDouble();
	}
	
	public String toString() {
		return resultName + ": " + latitude + ", " + longitude + ", " + openNow;
	}
}
